diff options
Diffstat (limited to 'app/[lng]/evcp/(evcp)/rfq-last/[id]/page.tsx')
| -rw-r--r-- | app/[lng]/evcp/(evcp)/rfq-last/[id]/page.tsx | 67 |
1 files changed, 57 insertions, 10 deletions
diff --git a/app/[lng]/evcp/(evcp)/rfq-last/[id]/page.tsx b/app/[lng]/evcp/(evcp)/rfq-last/[id]/page.tsx index 6819e122..1ccb7559 100644 --- a/app/[lng]/evcp/(evcp)/rfq-last/[id]/page.tsx +++ b/app/[lng]/evcp/(evcp)/rfq-last/[id]/page.tsx @@ -3,6 +3,9 @@ import { type SearchParams } from "@/types/table" import { getValidFilters } from "@/lib/data-table" import { searchParamsRfqAttachmentsCache } from "@/lib/b-rfq/validations" import { getRfqLastAttachments } from "@/lib/rfq-last/service" +import { RfqAttachmentsTable } from "@/lib/rfq-last/attachment/rfq-attachments-table" +import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert" +import { AlertCircle } from "lucide-react" interface IndexPageProps { // Next.js 13 App Router에서 기본으로 주어지는 객체들 @@ -16,21 +19,61 @@ interface IndexPageProps { export default async function RfqPage(props: IndexPageProps) { const resolvedParams = await props.params const lng = resolvedParams.lng - const id = resolvedParams.id + const rfqId = parseInt(resolvedParams.id, 10); - const idAsNumber = Number(id) + if (!rfqId || isNaN(rfqId) || rfqId <= 0) { + return ( + <div className="p-4"> + <Alert variant="destructive"> + <AlertCircle className="h-4 w-4" /> + <AlertTitle>오류</AlertTitle> + <AlertDescription> + 유효하지 않은 RFQ입니다. + </AlertDescription> + </Alert> + </div> + ); + } // 2) SearchParams 파싱 (Zod) // - "filters", "page", "perPage", "sort" 등 contact 전용 컬럼 - const searchParams = await props.searchParams - const search = searchParamsRfqAttachmentsCache.parse(searchParams) - const validFilters = getValidFilters(search.filters) + const searchParams = await props.searchParams; + const activeTab = searchParams.tab || '설계'; + + // 활성 탭에 따라 다른 파라미터 파싱 + const designSearch = activeTab === '설계' + ? searchParamsRfqAttachmentsCache.parse({ + ...searchParams, + // design_ prefix가 붙은 파라미터들 추출 + page: searchParams.design_page, + perPage: searchParams.design_perPage, + sort: searchParams.design_sort, + filters: searchParams.design_filters, + }) + : { page: 1, perPage: 10, sort: [], filters: [] }; + + const purchaseSearch = activeTab === '구매' + ? searchParamsRfqAttachmentsCache.parse({ + ...searchParams, + // purchase_ prefix가 붙은 파라미터들 추출 + page: searchParams.purchase_page, + perPage: searchParams.purchase_perPage, + sort: searchParams.purchase_sort, + filters: searchParams.purchase_filters, + }) + : { page: 1, perPage: 10, sort: [], filters: [] }; + + // 활성 탭의 데이터만 실제로 가져오기 + const [designData, purchaseData] = await Promise.all([ + activeTab === '설계' + ? getRfqLastAttachments({ ...designSearch }, rfqId, "설계") + : { data: [], pageCount: 0 }, + activeTab === '구매' + ? getRfqLastAttachments({ ...purchaseSearch }, rfqId, "구매") + : { data: [], pageCount: 0 } + ]); - const promises = getRfqLastAttachments({ - ...search, - filters: validFilters, - }, idAsNumber) // 4) 렌더링 return ( @@ -45,7 +88,11 @@ export default async function RfqPage(props: IndexPageProps) { </div> <Separator /> <div> - {/* <RfqAttachmentsTable promises={promises} rfqId={idAsNumber} /> */} + <RfqAttachmentsTable + rfqId={rfqId} + initialDesignData={designData} + initialPurchaseData={purchaseData} + /> </div> </div> ) |
